/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 * 
 * done - serialisation
 * http://www.jmdoudoux.fr/java/dej/chap-serialisation.htm
 * done - sort
 * http://stackoverflow.com/a/18302522
 */
package Controleur;

import Modele.Contact;
import Modele.Modele;
import Vue.Fenetre;
import java.awt.event.ActionEvent;
import java.io.File;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

/*
 * TODO
 * chargement image : id...
 * 
 * 
 */

/**
 * Carnet d'adresse.
 * @author Jordan Moss
 */
public class AdressBook {
    
    public Modele modele;
    Fenetre fenetre;

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        
        setLnF("Nimbus");//"Nimbus"
        try {
            UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
        } catch (Exception e) { }
        
        new AdressBook();
        
    }
    
    public AdressBook(){
        
        File dossier = new File(Util.path_to_dossier);
        if(!dossier.exists()){
            System.out.println("Le dossier d'images n'existe pas, il va etre cree.");
            dossier.mkdir();
            //TODO creer image par defaut : mettre dans un package
        }
        
        modele = new Modele();
        
        fenetre = new Fenetre(modele, this);
        modele.addEcouteur(fenetre);
        //modele.addListDataListener(fenetre);
        
        fenetre.setVisible(true);
    }
    
    
    public void ajoutGroupeActionPerformed(int indexGroupe) {
        modele.ajouterGroupe("Nouveau Groupe");
    }
    
    public void ajoutContactActionPerformed(ActionEvent e, int indexGroupe) {
        modele.ajouterContact(new Contact(), indexGroupe);
    }
    
    
    public void modifierContact(int indexGroupe, int indexContact, Contact contact){
        modele.modifierContact(contact, indexGroupe, indexContact);
    }
    
    
    public class ClicGroupeListener extends java.awt.event.MouseAdapter{
        
    }
    
    public static void setLnF(String desired){
        //<editor-fold defaultstate="collapsed" desc=" Nimbus Look and feel ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if (desired.equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Fenetre.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Fenetre.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Fenetre.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Fenetre.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>
    }
    
}

/*
java.awt.EventQueue.invokeLater(new Runnable() {
    public void run() {


    }
});*/


